package com.jmpt.fangbohui;

import android.content.Context;
import android.content.SharedPreferences;

import com.baidu.frontia.FrontiaApplication;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

import cn.jpush.android.api.JPushInterface;

public class MyApplication extends FrontiaApplication {

    private static MyApplication singleInstance;

    private static SharedPreferences sharedPreferences;

    @Override
    public void onCreate() {
        super.onCreate();

        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);

        singleInstance = this;
        
        initImageLoader(this);

    }

    public static MyApplication getSingleInstance() {

        return singleInstance;
    }


    public static SharedPreferences getSharedPreferences() {
        if (sharedPreferences == null) {
            sharedPreferences = singleInstance.getSharedPreferences(Constants.SharedPreferences.NAME, Context.MODE_PRIVATE);
        }
        return sharedPreferences;
    }

    /**
     * @param @param context
     * @return void
     * @throws
     * @Title: initImageLoader
     * @Description: 配置Universal Image Loader for Android （异步图片加载缓存组件）
     */
    public static void initImageLoader(Context context) {
        // This configuration tuning is custom. You can tune every option, you may tune some of
        // them,
        // or you can create default configuration by
        // ImageLoaderConfiguration.createDefault(this);
        // method.

        ImageLoaderConfiguration config =
                new ImageLoaderConfiguration.Builder(context).imageDownloader(new BaseImageDownloader(context, 20000, 90000)).memoryCacheSize(((int) Runtime.getRuntime().maxMemory()) / 12).memoryCache(new WeakMemoryCache()).tasksProcessingOrder(QueueProcessingType.LIFO).build();

        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);

    }

}
